<?php
namespace app\common\model;

use think\Model;
use think\Db;
use think\Config;
use think\Loader;
class LibraryCategory extends Model
{
    // 指定表名,不含前缀
    protected $name = 'library_category';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
	public $error;
	
	public function getError()
	{
		return $this->error;		
	}
	
	public function tablename()
	{
		return 'ex_'.$this->name;		
	}
	
	public function setError($str){
		$this->error = $str;
	}
	
	public function getList($parentid=-1)
	{
		if($parentid>=0) $sql_where['parentid'] = $parentid;
        $child_plaform = getChildAdminRegByPlaformId($this->plaform);
		$result = Db::name($this->name)->where(['admin_reg'=>['in',$child_plaform]])->where('isdelete=0')->where($sql_where)->select();
		return $result;
	}

	public function getInfo($id){
		$result = Db::name($this->name)->where('isdelete=0')->where('id',$id)->find();
		return $result;
	}
	
	/* 更新或者新增函数 */
	public function DataSave($data){
		$id = $data['id'];
		if(empty($id)) $data['admin_reg'] = $_SESSION['think']['reg'];
		!empty($id) ?  $ret = $this->allowField(true)->isUpdate(true)->save($data, ['id' => $id]) : $ret = $this->allowField(true)->isUpdate(false)->save($data);
		
		return $ret;
	}
	

	
}
